<template>
  <div class="ball-nav" ref="ballNavRef">
    <!-- 导航主体 -->
    <div class="ball-content" ref="ballContentRef">
      <!-- 悬浮球 -->
      <i :class="[icon, 'ball']" @click="$emit('input',true)" ref="ballRef">菜单</i>
      <!-- 菜单列表 -->
      <div class="nav-list" v-if="value">
        <slot />
      </div>
    </div>
    <!-- 遮罩层 -->
    <div class="mask-layer" v-show="value" ref="maskLayerRef" @click="$emit('input',false)"></div>
  </div>
</template>

<script>
export default {
  name: 'ball',
  props: {
    width: {
      type: Number,
      default: 20
    },
    value: {
      type: Boolean,
      required: true
    },
    color: {
      type: String,
      default: 'rgba(255, 255, 255,.9)'
    },
    icon: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      show: false
    }
  },
  created () {

  },
  mounted () {
    this.load()
  },
  methods: {
    load () {
      // this.$refs.ballRef.addEventListener('touchmove', e => {
      //   this.$refs.ballNavRef.style.left = e.targetTouches[0].pageX + 'px'
      //   this.$refs.ballNavRef.style.top = e.targetTouches[0].pageY + 'px'
      //   e.preventDefault()
      // })
      this.$refs.ballContentRef.style.width = this.width + 'vh'
      this.$refs.ballRef.style.background = this.color
    }
  }
}
</script>

<style scoped lang="less">
.ball-nav {
  position: fixed;
  top: 500px;
  left: 25px;
  z-index: 999;
  .ball-content {
    transform: translate(-25px,-25px);
    position: relative;
    z-index: 999;
    .ball {
      border: 5px solid #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      position: absolute;
      width: 60px;
      height: 60px;
      border-radius: 50%;
      font-size: 24px;
      z-index: 999;
      color: red;
      font-weight: 700;
    }
    .nav-list {
      position: relative;
      z-index: 999;
      width: 100%;
    }
  }
  .mask-layer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    // background: rgba(0,0,0,.5);
    z-index: 998;
  }
}
</style>
